package org.compression.services;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

import org.common.util.PasswordEncrypt;
import org.compression.mapper.BaseMapper;
import org.compression.mapper.UserManagmentMapper;
import org.compression.services.imp.BaseServiceImp;
import org.model.auth.User;
import org.model.business.UserManagment;
import org.model.comm.Page;
import org.model.comm.UpdateModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


public abstract class UserManagmentSerivce<T extends BaseMapper,M>  extends BaseServiceImp<T,M>{
	
	
	@Autowired
	UserManagmentMapper mUserManagmentMapper;
	
	@Override
	public Object add(UpdateModel<M> mModel) {
		Page mPage =mModel.getmPage();
		UserManagment user=(UserManagment) mModel.getmBookMagament();
		try {
			user.setPassword(PasswordEncrypt.encodeByMd5(user.getPassword()));
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return mUserManagmentMapper.insertSelective(user);
	}
	
	@Override
	public void updateByPrimaryKeySelective(UpdateModel<M> mAddModel) {
		Page mPage =mAddModel.getmPage();
		UserManagment user=(UserManagment) mAddModel.getmBookMagament();
		user.setPassword(null);
		mUserManagmentMapper.updateByPrimaryKeySelective(user);
	}
	

	public	abstract void updatePassWord(UpdateModel<UserManagment> mAddModel);
	

	
	
	
	
	
}
